# Copyright 2020 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

load("@rules_cc//cc:cc_library.bzl", "cc_library")
load("@rules_python//sphinxdocs:sphinx_docs_library.bzl", "sphinx_docs_library")
load("//pw_build:compatibility.bzl", "incompatible_with_mcu")

package(
    default_visibility = ["//visibility:public"],
)

licenses(["notice"])

# This target is the backend for //pw_log.
cc_library(
    name = "pw_log_basic",
    hdrs = [
        "public_overrides/pw_log_backend/log_backend.h",
    ],
    strip_include_prefix = "public_overrides",
    deps = [":extension"],
)

# This target directly exposes the log_basic.h header. Outside of this package,
# only depend on it directly if you are using parts of the pw_log_basic
# interface which are not in the pw_log interface, such as the
# `pw::log_basic::SetOutput` function.
cc_library(
    name = "extension",
    srcs = [
        "log_basic.cc",
    ],
    hdrs = [
        "public/pw_log_basic/log_basic.h",
    ],
    strip_include_prefix = "public",
    deps = [
        ":config",
        "//pw_log:pw_log.facade",
        "//pw_preprocessor",
        "//pw_string:builder",
        "//pw_sys_io",
    ],
)

cc_library(
    name = "config",
    hdrs = [
        "pw_log_basic_private/config.h",
    ],
    visibility = ["//visibility:private"],
    deps = [
        ":config_override",
    ],
)

label_flag(
    name = "config_override",
    build_setting_default = "//pw_build:default_module_config",
)

# The impl of pw_log_basic is an empty library: it's so basic that there's no
# risk of circular dependencies.
cc_library(
    name = "impl",
)

cc_library(
    name = "log_string_handler",
    srcs = [
        "log_string_handler.cc",
    ],
    deps = [
        ":extension",
        "//pw_log_string:handler.facade",
    ],
)

# This config setting is active if pw_log_basic was selected as the backend for pw_log.
config_setting(
    name = "is_active_backend",
    flag_values = {
        "//pw_log:backend": ":pw_log_basic",
    },
)

sphinx_docs_library(
    name = "docs",
    srcs = [
        "docs.rst",
    ],
    prefix = "pw_log_basic/",
    target_compatible_with = incompatible_with_mcu(),
)
